package com.only4play.productcenter.infrastructure.convert;

/**
 * @author hinzzz www.hinzzz.cn 157957329@qq.com
 * 2024-03-06
 */
import com.only4play.productcenter.api.constants.ValueType;

import javax.persistence.AttributeConverter;

public class ValueTypeConverter implements AttributeConverter<ValueType,Integer> {

  @Override
  public Integer convertToDatabaseColumn(ValueType valueType) {
    return valueType.getCode();
  }

  @Override
  public ValueType convertToEntityAttribute(Integer code) {
    return ValueType.of(code).orElse(null);
  }
}